/**
 * 
 */
package com.ideal.framework.pagetag;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author mengmingkuo
 * @create time 2008-7-15 14:04:15
 */
public class DataList {
	 private int pageSize;
	    private int currentPage;
	    private int maxCount;
	    private Map addinInfo;
	    private String uri;
	    private String pageKey;
	    private List nowlist;

	    public DataList()
	    {
	        pageSize = 0;
	        currentPage = 1;
	        maxCount = 0;
	        addinInfo = new TreeMap();
	        uri = "";
	        pageKey = "page";
	        nowlist = new ArrayList();
	    }

	    public DataList(List list, int total, int pagenum, int npage)
	    {
	        pageSize = 0;
	        currentPage = 1;
	        maxCount = 0;
	        addinInfo = new TreeMap();
	        uri = "";
	        pageKey = "page";
	        nowlist = new ArrayList();
	        nowlist = list;
	        maxCount = total;
	        pageSize = pagenum;
	        currentPage = npage;
	    }

	    public List getNowlist()
	    {
	        return nowlist;
	    }

	    public void setNowlist(List nowlist)
	    {
	        this.nowlist = nowlist;
	    }

	    public int getStart()
	    {
	        if(currentPage * pageSize > maxCount)
	            return (getMaxPage() - 1) * pageSize + 1;
	        else
	            return (currentPage - 1) * pageSize + 1;
	    }

	    public int getEnd()
	    {
	        if(currentPage * pageSize > maxCount)
	            return maxCount;
	        else
	            return currentPage * pageSize;
	    }

	    public int getMaxPage()
	    {
	        int maxPage = (int)Math.ceil((double)maxCount / (double)pageSize);
	        if(maxPage <= 0)
	            maxPage = 1;
	        return maxPage;
	    }

	    public String getPageKey()
	    {
	        return pageKey;
	    }

	    public int getPrevPage()
	    {
	        int prevPage = getCurrentPage() - 1;
	        if(prevPage <= 0)
	            prevPage = 1;
	        return prevPage;
	    }

	    public int getNextPage()
	    {
	        int nextPage = getCurrentPage() + 1;
	        if(nextPage > getMaxPage())
	            nextPage = getMaxPage();
	        return nextPage;
	    }

	    public int getPageSize()
	    {
	        return pageSize;
	    }

	    public void setPageSize(int pageSize)
	    {
	        this.pageSize = pageSize;
	    }

	    public int getCurrentPage()
	    {
	        int maxPage = getMaxPage();
	        if(currentPage > maxPage)
	            return maxPage;
	        else
	            return currentPage;
	    }

	    public void setCurrentPage(int currentPage)
	    {
	        this.currentPage = currentPage;
	    }

	    public int getMaxCount()
	    {
	        return maxCount;
	    }

	    public void setMaxCount(int maxCount)
	    {
	        this.maxCount = maxCount;
	    }

	    public void addinInfo(String key, String value)
	    {
	        addinInfo.put(key, value);
	    }

	    public Map getAddinInfo()
	    {
	        return addinInfo;
	    }

	    public void setPageKey(String string)
	    {
	        pageKey = string;
	    }

	    public String getUri()
	    {
	        return uri;
	    }

	    public void setUri(String string)
	    {
	        uri = string;
	    }
}
